package com.emmmya.ocs.modules.system.vo;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.emmmya.ocs.modules.system.entity.User;
import com.emmmya.ocs.common.base.BaseVo;
import com.emmmya.ocs.common.utils.DateUtils;
import lombok.Data;
import lombok.ToString;
import org.thymeleaf.util.StringUtils;

/**
 * @description: mybatis的分页查询条件
 * @author: 咕噜肉IT小店-黑医
 * @createDate: 2020-12-24
 * @version: 1.0
 */
@Data
@ToString
public class UserVo extends BaseVo<User> {
    private String username;

    private String name;

    private String qq;

    private String email;

    private String telPhone;

    /**
     * 当前页码
     */
    private Integer page = 1;

    /**
     * 每页数量
     */
    private Integer limit = 10;

    /**
     * 开始时间
     */
    private String s_date;

    /**
     * 结束时间
     */
    private String e_date;

    /**
     *
     * @return
     */
    private String lastLoginDate;

    @Override
    public QueryWrapper<User> createWrapper() {
        try {
            wrapper = new QueryWrapper<>();
            if(!StringUtils.isEmpty(this.getUsername())) {
                wrapper.eq("username", this.getUsername());
            }
            if(!StringUtils.isEmpty(s_date)){
                //>=
                wrapper.ge("date(create_time)", DateUtils.parseDate(s_date+" 00:00:00","yyyy-MM-dd HH:mm:ss"));
            }
            if(!StringUtils.isEmpty(e_date)){
                //<=
                wrapper.le("date(create_time)", DateUtils.parseDate(e_date+" 23:59:59","yyyy-MM-dd HH:mm:ss"));
            }
            if(!StringUtils.isEmpty(lastLoginDate)){
                //>=
                wrapper.ge("date(last_login_time)", DateUtils.parseDate(lastLoginDate+" 00:00:00","yyyy-MM-dd HH:mm:ss"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return wrapper;
    }

    @Override
    public IPage<User> createPage() {
        return new Page<User>(this.getPage(),this.getLimit());
    }
}
